package com.zxy.ziems.server.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.domain.Agreement;
import com.zxy.ziems.server.dto.AgreementDto;
import com.zxy.ziems.server.dto.AgreementQueryDto;
import com.zxy.ziems.server.service.AgreementService;
import com.zxy.ziems.server.vo.AgreementVo;
import com.zxy.ziems.server.vo.OrgVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName AgreementController
 * @Description
 * @Author 邓伟
 * @Date 2023/11/29 10:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/agreement")
public class AgreementController {

    @Autowired
    private AgreementService agreementService;

    @PostMapping("/addOrUpdate")
    public JsonResponse addOrUpdate (@RequestBody @Validated AgreementDto agreementDto) {
        agreementService.addOrUpdate(agreementDto);
        return JsonResponse.SUCCESS();
    }

    @GetMapping("/delete")
    public JsonResponse delete (@RequestParam(value = "agreementId") String agreementId) {
        agreementService.delete(agreementId);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("/page/list")
    public JsonResponse<PageResult<AgreementVo>> pageList (@RequestBody AgreementQueryDto agreementQueryDto) {
        PageResult<AgreementVo> pageResult = agreementService.pageList(agreementQueryDto);
        return JsonResponse.SUCCESS(pageResult);
    }

    @GetMapping("/list")
    public JsonResponse<List<Agreement>> list () {
        List<Agreement> list = agreementService.list();
        return JsonResponse.SUCCESS(list);
    }
}
